package com.nbjtjc.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.nbjtjc.safe.model.safe.SafeBasisClassify;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class InspectObjectParse {
    public static void main(String[] args) throws IOException {
        Document d= Jsoup.connect("http://www.safetyhua.com/Public/Login").get();
        //获取仿登录的数据
        d.getElementById("AccountCode").attr("value","00274_hky");
        d.getElementById("Password").attr("value","hky101112");
        //用map来存储数据
        Map map=new HashMap();
        map.put("AccountCode","00274_hky");
        map.put("Password","hky101112");

        //登录，获取cookies
        Connection.Response login=Jsoup.connect("http://www.safetyhua.com/Public/LoginPost")
                .ignoreContentType(true)
                .followRedirects(true)
                .data(map)
                .method(Connection.Method.POST)
                .execute()
                .charset("utf-8");

        //模拟成功后，自己想获取的数据，并且要求携带cookies数据

        Document index=Jsoup.connect("http://www.safetyhua.com/DangerLawGistClassify/GetClassify?timestamp=1613530268273&type=Public")
                .ignoreContentType(true).cookies(login.cookies()).get();
        //打印数据网页
        System.out.println(index.body().text());
        String jsonString= index.body().text();
        JSONObject jsonObject=JSON.parseObject(jsonString);
        JSONArray jsonArray=jsonObject.getJSONArray("data");
        for(int i=0;i<jsonArray.size();i++){
            JSONObject classify=jsonArray.getJSONObject(i);
            SafeBasisClassify safeBasisClassify=classify.toJavaObject(SafeBasisClassify.class);
            System.out.println(safeBasisClassify.toString());
        }


    }


}
